#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <math.h>
#include "game.h"

void menu()
{
    printf("*****************************\n");
    printf("*********  1.play   *********\n");
    printf("*********  0.exit   *********\n");
    printf("*****************************\n");
}

void game()
{
    //存储数据，二维数组
    char board[ROW][COL];
    //初始化棋盘，初始化空格
    InitBoard(board,ROW,COL);
    //打印棋盘
    DisplayBoard(board,ROW,COL);
    char ret = 0;//接收游戏状态
    while(1)
    {
        //玩家下
        PlayerMove(board,ROW,COL);
        DisplayBoard(board,ROW,COL);
        //判断玩家是否赢
        char ret = IsWin(board,ROW,COL);
        if (ret != 'C')
           break;
        //电脑下        
        ComputerMove(board,ROW,COL);
        DisplayBoard(board,ROW,COL);
        //判断电脑是否赢
        ret = IsWin(board,ROW,COL);
        if (ret != 'C')
           break;
    }
    if(ret == '*')
    {
        printf("玩家赢\n");
        //DisplayBoard(board,ROW,COL);
    }
    else if(ret == '#')
    {
        printf("电脑赢\n");
        //DisplayBoard(board,ROW,COL);
    }
    else
    {
        printf("平局\n");
    }
    DisplayBoard(board,ROW,COL);

}
int main()
{
    int input = 0;
    srand((unsigned int)time(NULL));

    do
    {
        menu();
        printf("请选择:>\n");
        scanf("%d",&input);
        switch(input)
        {
            case 1:
                game();
                break;
            case 0:
                printf("不玩啦\n");
                break;
            default:
                printf("选择错误\n");
                break;
        }
    } 
    while (input);
    
    
    return 0;
}